package com.kust.smarthome.web.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.kust.smarthome.web.model.Notice;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author iAuzre
 * @since 2021-07-06
 */
@Repository
public interface NoticeMapper extends BaseMapper<Notice> {

    @Select("select content,created,state\n" +
            "from notice\n" +
            "where device_id=#{deviceId} and type_id=#{typeId}\n" +
            "order by created desc")
    List<Notice> selectMessage2(@Param("typeId")Integer typeId,@Param("deviceId")Integer deviceId);

    @Select("select type_id,device_id\n" +
            "from notice\n" +
            "where user_id=#{userId}\n" +
            "GROUP BY device_id,type_id\n" +
            "order by type_id")
    List<Notice> selectMessage1(Integer userId);

    @Update("update notice\n" +
            "set state=1\n" +
            "where device_id=#{deviceId} and type_id=#{typeId} and user_id=#{userId}")
    void updateState(@Param("userId")Integer userId,@Param("typeId")Integer typeId,@Param("deviceId")Integer deviceId);
}
